package org.geektimes.configuration.microprofile.config;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigBuilder;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @Author: menglinggang
 * @Date: 2021-03-15
 * @Time: 5:29 下午
 */
public class DefaultConfigProviderResolver extends ConfigProviderResolver {


    private Config config = null;

    public DefaultConfigProviderResolver(){
        ServiceLoader<Config> load = ServiceLoader.load(Config.class, getClass().getClassLoader());
        Iterator<Config> iterator = load.iterator();
        while (iterator.hasNext()) {
            config =  iterator.next();
            return;
        }
        throw new IllegalStateException("No Config implementation found!");
    }

    @Override
    public Config getConfig() {
        return config;
    }

    @Override
    public Config getConfig(ClassLoader classLoader) {
        return null;
    }

    @Override
    public ConfigBuilder getBuilder() {
        return null;
    }

    @Override
    public void registerConfig(Config config, ClassLoader classLoader) {

    }

    @Override
    public void releaseConfig(Config config) {

    }
}
